//
//  HRZTool.m
//  EMarket
//
//  Created by 石头 on 2018/8/30.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZTool.h"
// Controllers

// Models
#import "HRZUserInfo.h"
#import "HRZLocalOrderStatusModel.h"

#import "HRZHomeCarouselModel.h"
#import "HRZHomeBigbrandModel.h"
#import "HRZHomeThemeModel.h"
#import "HRZHomeHotClassifyModel.h"

#import "HRZHomeRecommentBaseItem.h"
// Views

// Vendors

// Categories

// Others
#import "MJExtension.h"


@interface HRZTool ()

@end

@implementation HRZTool

+ (void)setUserShopInfo:(HRZUserInfo *)userInfo {
    NSMutableDictionary *dic = [userInfo mj_keyValues];
    [self saveLocalObj:dic withKey:@"UserShopInfo"];
}
+ (HRZUserInfo *)getUserShopInfo {
    if (![self getUserLoginStatus]) {
        return nil;
    }
    
    NSDictionary *dic = [self getLocalObjWithKey:@"UserShopInfo"];
    HRZUserInfo *userInfo = [HRZUserInfo mj_objectWithKeyValues:dic];
    return userInfo;
}

+ (NSInteger)getUserShopId {
    HRZUserInfo *userInfo = [self getUserShopInfo];
    return [userInfo.storeId integerValue];
}

+ (void)setUserLoginStatus:(BOOL)isLogin {
    [self saveLocalBool:isLogin withKey:@"userLoginStatus"];
}
+ (BOOL)getUserLoginStatus {
    return [self getLocalBoolWithKey:@"userLoginStatus"];
}

+ (NSArray<HRZLocalOrderStatusModel *> *)getLocalFileOrderStatusInfo {
    NSArray *array = [HRZLocalOrderStatusModel mj_objectArrayWithFilename:@"MyCenterFlow.plist"];
    return array;
}

+ (HRZHomeRecommentBaseItem *)homeRecommentNetItemTurnIOSItem:(id)item {

    HRZHomeRecommentBaseItem *baseItem = [HRZHomeRecommentBaseItem new];
    
    if ([item isKindOfClass:[HRZHomeCarouselModel class]]) {    //  轮播图
        HRZHomeCarouselModel *model = (HRZHomeCarouselModel*)item;
        baseItem.itemType = HRZHomeRecommentItemTypeCarousel;
        baseItem.itemId = model.carouselId;
        baseItem.itemName = @"";
        baseItem.itemDesc = @"";
        baseItem.itemImageUrl = model.carouselImg;
        
        baseItem.carouselSkipId = model.skipId;
        baseItem.carouselSkipType = model.skipType;
        baseItem.carouselSkipURL = model.skipUrl;
    } else if ([item isKindOfClass:[HRZHomeThemeModel class]]) {    //  主题
        HRZHomeThemeModel *model = (HRZHomeThemeModel*)item;
        baseItem.itemType = HRZHomeRecommentItemTypeTheme;
        baseItem.itemId = model.themeId;
        baseItem.itemName = model.themeName;
        baseItem.itemDesc = model.introduce;
        baseItem.itemImageUrl = model.themeUrl;
        
    } else if ([item isKindOfClass:[HRZHomeHotClassifyModel class]]) {     //  热门分类
        HRZHomeHotClassifyModel *model = (HRZHomeHotClassifyModel*)item;
        baseItem.itemType = HRZHomeRecommentItemTypeHotClassify;
        baseItem.itemId = model.cateId;
        baseItem.itemName = model.className;
        baseItem.itemDesc = model.introduce;
        baseItem.itemImageUrl = model.classifyImg;
        
    } else if ([item isKindOfClass:[HRZHomeBigbrandModel class]]) {     //  大牌
        HRZHomeBigbrandModel *model = (HRZHomeBigbrandModel*)item;
        baseItem.itemType = HRZHomeRecommentItemTypeBigbrand;
        baseItem.itemId = model.trademarkId;
        baseItem.itemName = model.trademarkName;
        baseItem.itemDesc = model.introduce;
        baseItem.itemImageUrl = model.trademarkImg;
        
    }
    
    return baseItem;
}

+ (NSString *)getCurrentPhoneDeviceUuid {
    [[NSUUID UUID] UUIDString];
    return @"";
}

+ (NSString *)hrz_GetLastOpenAppVersion {
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"hrz_AppVersion"];
}

+ (void)hrz_SaveNewAppVersion:(NSString *)appVersion {
    [[NSUserDefaults standardUserDefaults] setObject:appVersion forKey:@"hrz_AppVersion"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - ----------  Base Save  ----------
+ (void)saveLocalObj:(id)obj withKey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (id)getLocalObjWithKey:(NSString *)key {
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

+ (void)saveLocalBool:(BOOL)isTure withKey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] setBool:isTure forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)getLocalBoolWithKey:(NSString *)key {
    return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}

@end
